'use strict'

const path = require('path')

module.exports = (appInfo) => {
  const prefix = 'yqfk-data' // 文件夹
  const dbName = 'yqfk_data_test' // 数据库
  const tablePrefix = 'yqfk' // 表前缀
  const storageDir = process.platform == 'linux' ? `/data/node/static/${prefix}` : path.join(__dirname, `../app/storage`)

  const config = {
    prefix,

    name: '疫情防控',

    host: 'http://127.0.0.1:7001',
    h5: 'http://localhost:3500/h5',
    client: 'http://127.0.0.1:3001',

    dbName,

    // 资源存储路径
    storageDir,

    // 上次文件路径
    uploadDir: storageDir + '/public',

    mongodb: `mongodb://root:FY8iDztMBKDIejpx@36.99.193.53:27017/${dbName}?authSource=admin`,

    // 注意，开启此模式后，应用就默认自己处于反向代理之后，
    // 会支持通过解析约定的请求头来获取用户真实的 IP，协议和域名。
    // 如果你的服务未部署在反向代理之后，请不要开启此配置，以防被恶意用户伪造请求 IP 等信息。
    proxy: true,

    // 超级手机号（测试用）
    superMobile: ['13812345678'],

    // 聚合
    juhe: {
      keys: {
        // 短信
        sendSms: '3af84db18c621d9b92238e2abce15de2',
      },
      sendSms: {
        // 注册
        register: '92246',
        // 登陆
        login: '215058',
        // 忘记密码/或修改密码
        password: '92246',
      },

      // 快递查询
      express: '52f2db2b9bcf560062b7cdcb488d59c5',
    },
  }

  // Cookie签名秘钥
  config.keys = appInfo.name + '_1605061497228_1857'

  config.middleware = [
    // 'requestLog',
    'koaLogger',
  ]

  config.mongoose = {
    url: config.mongodb,
  }

  config.security = {
    csrf: false,
  }

  config.cors = {
    origin: (ctx) => ctx.headers.origin,
    credentials: true,
    // allowHeaders: 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With',
    // allowMethods: 'PUT,POST,GET,DELETE,OPTIONS',
  }

  config.static = {
    dir: [
      { prefix: '/', dir: config.uploadDir },
      {
        prefix: '/',
        dir: path.join(__dirname, '../app/public'),
      },
    ],
  }

  // jwt
  config.jwt = {
    secret: config.keys + 'jwt2021',
    // 有效期
    expiresIn: '14d',
  }

  config.session = {
    key: prefix + 'SESSION_ID',
    // 7天
    maxAge: 1000 * 60 * 60 * 24 * 7, // 毫秒
    httpOnly: true,
    encrypt: true,
    renew: true, // 延长会话有效期
  }

  config.sessionMongoose = {
    name: 'Session',
  }

  config.jst = {
    baseURL: 'https://open.erp321.com/api/open/query.aspx', // 正式环境
    partnerId: 'b5bc4d47edec893866d0799b99f37d3f',
    partnerKey: '742c2167bd7bd5020e9d4ae507547975',
    token: '0c996b3d1ec8c20ae1bc3e3a35003560',
    // debug: true,
  }

  config.jax = {
    mongoose: {
      prefix: tablePrefix,
    },
  }

  config.uvcMallApi = {
    baseURL: 'http://t.mall.uvsnake.com/jjc',
    debug: true,
    headers: {
      'App-Type': 1,
      'App-Env': 'test',
    },
  }

  config.uvcV4Mysql = {
    host: '139.9.141.62',
    user: 'root',
    password: 'UvcM123*!',
    database: 'uvc_pp_test',
    port: 3306,
  }

  config.uvcV5Mysql = {
    host: '119.3.249.105',
    user: 'root',
    password: 'UvcM123*!',
    database: 'daysp_test',
    port: 3306,
  }

  config.pptvApi = {
    baseURL: 'https://coapi.pptv.com',
    appKey: 'c94902c7217b9d54cff164cb07680dcf',
    appSecret: '70f3ebf93fa86e343dba11dfb720954e',
    debug: true,
  }

  config.dict = require('./dict')
  config.constant = require('./constant')

  config.mqtt = {
    port: {
      tcp: 1883,
      ws: 8083,
    },
    username: 'mjmqtt',
    password: 'mjmqtt2022EDSX',
    server: 'ws://localhost:7777',
  }

  return config
}
